package cn.meibang.common.beauty.provider.dao;

import cn.meibang.common.beauty.provider.domain.BeautyConsultationOrderUserConsultantLatest;

import java.util.Map;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

public class BeautyConsultationOrderUserConsultantLatestSqlProvider {

    public String selectPageByUserIdAndOpenidAndStoreId(Map params) {
        Object userId = params.get("userId");
        Object openid = params.get("openid");
        StringBuilder sqlSb = new StringBuilder();
        sqlSb.append("select ");
        sqlSb.append("id, tag, user_id, openid, store_id, store_name, consultant_id, consultant_name, consultant_img ");
        sqlSb.append("from beauty_consultation_order_user_consultant_latest ");
        sqlSb.append("where store_id = #{storeId} ");
        if (userId != null && (Long) userId > 0) {
            sqlSb.append("and user_id = #{userId,jdbcType=BIGINT} ");
        } else if (openid != null) {
            sqlSb.append("and openid = #{openid,jdbcType=VARCHAR} ");
        }
        sqlSb.append("order by id desc ");
        sqlSb.append("limit #{offset}, #{size} ");
        return sqlSb.toString();
    }

    public String insertSelective(BeautyConsultationOrderUserConsultantLatest record) {
        BEGIN();
        INSERT_INTO("beauty_consultation_order_user_consultant_latest");

        if (record.getId() != null) {
            VALUES("id", "#{id,jdbcType=BIGINT}");
        }

        if (record.getTag() != null) {
            VALUES("tag", "#{tag,jdbcType=VARCHAR}");
        }

        if (record.getUserId() != null) {
            VALUES("user_id", "#{userId,jdbcType=BIGINT}");
        }

        if (record.getOpenid() != null) {
            VALUES("openid", "#{openid}");
        }

        if (record.getStoreId() != null) {
            VALUES("store_id", "#{storeId,jdbcType=BIGINT}");
        }

        if (record.getStoreName() != null) {
            VALUES("store_name", "#{storeName}");
        }

        if (record.getConsultantId() != null) {
            VALUES("consultant_id", "#{consultantId,jdbcType=BIGINT}");
        }

        if (record.getConsultantName() != null) {
            VALUES("consultant_name", "#{consultantName,jdbcType=VARCHAR}");
        }

        if (record.getConsultantImg() != null) {
            VALUES("consultant_img", "#{consultantImg,jdbcType=VARCHAR}");
        }

        return SQL();
    }

    public String updateByPrimaryKeySelective(BeautyConsultationOrderUserConsultantLatest record) {
        BEGIN();
        UPDATE("beauty_consultation_order_user_consultant_latest");

        if (record.getTag() != null) {
            SET("tag = #{tag,jdbcType=VARCHAR}");
        }

        if (record.getUserId() != null) {
            SET("user_id = #{userId,jdbcType=BIGINT}");
        }

        if (record.getOpenid() != null) {
            SET("openid = #{openid}");
        }

        if (record.getStoreId() != null) {
            SET("store_id = #{storeId,jdbcType=BIGINT}");
        }

        if (record.getStoreName() != null) {
            SET("store_name = #{storeName}");
        }

        if (record.getConsultantId() != null) {
            SET("consultant_id = #{consultantId,jdbcType=BIGINT}");
        }

        if (record.getConsultantName() != null) {
            SET("consultant_name = #{consultantName,jdbcType=VARCHAR}");
        }

        if (record.getConsultantImg() != null) {
            SET("consultant_img = #{consultantImg,jdbcType=VARCHAR}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }
}